#region Using References

using System;
using System.Diagnostics.Contracts;
using System.IO;
using Ionic.Zip;

#endregion

namespace Beaker.Services.FileSystem.Zip
{
	internal class ZipFileEntry
		: ZipFSEntry, IFile
	{
		private readonly ZipFileSystemService _root;
		private readonly ZipEntry _entry;

		public ZipFileEntry( ZipFileSystemService root, IFolder parent, ZipEntry entry, string fileName )
			: base( parent, fileName )
		{
			Contract.Requires<ArgumentNullException>( root != null );
			Contract.Requires<ArgumentNullException>( parent != null );
			Contract.Requires<ArgumentNullException>( entry != null );

			_root = root;
			_entry = entry;
		}

		/// <summary>
		/// Open the file for reading
		/// </summary>
		/// <returns>A stream of the content of the file</returns>
		public Stream OpenRead()
		{
			return _entry.OpenReader();
		}

		/// <summary>
		/// Open the text-file for reading
		/// </summary>
		/// <returns>A text-reader with the content of the file</returns>
		public TextReader OpenText()
		{
			return new StreamReader( OpenRead() );
		}
	}
}